package com.cd2cd.code_template.util;

import com.cd2cd.code_template.vo.BaseRes;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationTargetException;

@Slf4j
public class ExceptionUtils {

    public static void setExceptionMsg(Throwable e, BaseRes<String> res) {
        Throwable ee = e.getCause();
        if(ee != null) {
            while(ee instanceof InvocationTargetException) {
                ee = ((InvocationTargetException) ee).getTargetException();
            }
        } else {
            ee = e;
        }
        res.setMsg(ee.getClass().getSimpleName());
        log.error("error={}", e.getMessage(), ee);
    }

}
